package com.class04.controller;

import com.class04.pojo.User;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/12/12 15:30
 */
@RestController
@RequestMapping("user")
public class UserController {
    @GetMapping
    public List<User> getPageData(@RequestParam(required = false,defaultValue = "1" ) int page ,
                                  @RequestParam(required = false,defaultValue = "10") int size){
        ArrayList<User> users = new ArrayList<>();
        System.out.println("page = " + page + ", size = " + size);
        users.add(new User(1,"zhangsan",12));
        users.add(new User(1,"zhangsan",12));
        users.add(new User(1,"zhangsan",12));
        List<User> collect = users.stream().distinct().collect(Collectors.toList());
        return collect;
    }


    @PostMapping
    public User saveUser(@RequestBody User user){
        return user;
    }

    @PutMapping
    public User putUser(@RequestBody User user){
        return user;
    }

    @DeleteMapping("{ids}")
    public Integer deleteUser(@PathVariable(value = "ids") Integer id){
        return id;
    }

    @GetMapping("{ids}")
    public Integer detailUser(@PathVariable(value = "ids") Integer id){
        return id;
    }

    @GetMapping("search")
    public List<User> getSearchData(String keyword , @RequestParam(required = false,defaultValue = "1" ) int page ,
                                  @RequestParam(required = false,defaultValue = "10") int size){
        ArrayList<User> users = new ArrayList<>();
        System.out.println("keyword = " + keyword + ", page = " + page + ", size = " + size);
        users.add(new User(1,"zhangsan",12));
        users.add(new User(1,"zhangsan",12));
        users.add(new User(1,"zhangsan",12));
        List<User> collect = users.stream().distinct().collect(Collectors.toList());
        return collect;
    }



}
